const parseJson = (o) => {
    let result;

    try {
        result = JSON.parse(o);
        if (typeof(result) !== 'object') {
            result = o;
        }
    } catch(e) {
        result = o;
    }

    return result;
};

export default {
    // 存储localStorage
    set: function(key, value) {
        let ls = window.localStorage;
        if (arguments.length > 1) {
            return typeof(value) != 'object' ? ls.setItem(key, value) : ls.setItem(key, JSON.stringify(value));
        }
        return parseJson(ls.getItem(key));
    },
    // 取localStorage
    get: function(key) {
        let ls = window.localStorage;
        return ls.getItem('key');
    }
}
